<?php
require_once "interface/Gi_Paginator_Adapter_Interface.php";   
require_once "Gi_Db.php";
require_once "Gi_Sql_Writer.php";
Class Gi_Paginator_Select implements Gi_Paginator_Adapter_Interface {
  protected $_select = null;   
  
  protected $_select_count = null;
  
  protected $_count = null;   
  
  protected $_db = null;
  
  private function _get_count() {
    $regex = "FROM(.*)";
    if (eregi($regex,$this->_select,$match)) {
      $this->_select_count = "SELECT count(*) " . $match[0];
      
      return (int) Gi_Db::get_lookup($this->_select_count);
    }
  }
  
  public function __construct ($select) {
    $this->_select = $select;
    $this->_count = $this->_get_count();
  }
  
  public function get_items ($offset, $items_per_page) {
    $sql = new Gi_Sql_Writer("select","*","bla");
    $sql->set_sql($this->_select);
    $sql->add_limit("$offset, $items_per_page");
    //echo $sql;
    return Gi_Db::get_recordset($sql);
    //return array_slice($this->_array, $offset, $item_per_page);
  }

  public function count() {
    return $this->_count;
  }
}
?>
